home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group03a.txt / 000074_icon-group-sender_Tue Apr 15 12:26:33 2003.msg < prev    next >
Internet Message Format  |  2003-12-22  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h3FJQFM11960
  4.     for icon-group-addresses; Tue, 15 Apr 2003 12:26:15 -0700 (MST)
  5. Message-Id: <200304151926.h3FJQFM11960@baskerville.CS.Arizona.EDU>
  6. From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
  7. X-Newsgroups: comp.lang.icon
  8. Subject: Re: Simplifying Integer Arithmetic
  9. X-Priority: 3
  10. X-MSMail-Priority: Normal
  11. X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
  12. X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
  13. Date: Tue, 15 Apr 2003 15:18:01 GMT
  14. X-Complaints-To: abuse@verizon.net
  15. To: icon-group@cs.arizona.edu
  16. Errors-To: icon-group-errors@cs.arizona.edu
  17. Status: RO
  18.  
  19. Perhaps there is a way to have the best of both worlds. We could add the
  20. configuration parameter ROUNDS_TO_0 that will indicate whether C integer
  21. division / modulo rounds to 0 on this platform. This macro can be used to
  22. make sure that the more complicated versions of div3 / mod3 are used only
  23. when necessary, as follows:
  24.  
  25. /*
  26.  * div3 - integer divide with overflow checking (always rounds to 0)
  27.  */
  28. word div3(a, b)
  29. word a, b;
  30. {
  31. #if ROUNDS_TO_0
  32.     /* Simplified implementation, C result needs no adjusting */
  33. #else
  34.     /* More complicated implementation, adjusts C result if necessary to get
  35. rounding to 0 */
  36. #endif
  37. }
  38.  
  39. Within the file "src/h/config.h", we can guarantee that ROUNDS_TO_0 is
  40. defined with the following preprocessor directives:
  41.  
  42. #ifndef ROUNDS_TO_0
  43.    #if ( 5 / (-3) == -1 ) && ( (-5) / 3 == -1 ) && ( (-5) / (-3) == 1 )
  44.       #define ROUNDS_TO_0 1
  45.    #else
  46.       #define ROUNDS_TO_0 0
  47.    #endif
  48. #endif                                  /* ROUNDS_TO_0 */
  49.  
  50. If there is some platform for which this does not set ROUNDS_TO_0 to the
  51. appropriate value, you can set it in 'src/h/define.h'.
  52.  
  53.  
  54.  
  55.